<template>
  <div class="main-aside">
    <el-aside width="220px">
      <el-menu
        :default-active="$route.path"
        class="el-menu-vertical-demo"
        text-color="#37383C"
        active-text-color="#5d9aff"
        unique-opened
        router
      >
        <div v-for="(item, index) in menuList" :key="index">
          <!-- 没有子菜单的分类 -->
          <el-menu-item v-if="!item.children" :index="`${item.path}`">
            <template #title>
              <i :class="`iconfont ${item.mate ? item.mate.icon : ''}`"></i>
              <span>{{ item.mate ? item.mate.title : '' }}</span>
            </template>
          </el-menu-item>
          <!-- 有子菜单 -->
          <el-submenu v-else :index="`${item.path}`">
            <template #title>
              <i :class="`iconfont ${item.mate ? item.mate.icon : ''}`"></i>
              <span>{{ item.mate ? item.mate.title : '' }}</span>
            </template>
            <el-menu-item
              :index="`${item.path}/${child.path}`"
              v-for="child in item.children"
              :key="child.id"
            >{{ child.mate ? child.mate.title : '' }}</el-menu-item>
          </el-submenu>
        </div>
      </el-menu>
    </el-aside>
  </div>
</template>

<script>
import { reactive, ref, toRefs, onMounted } from 'vue'
import { useRouter } from 'vue-router'
export default {
  props: ['title'],
  setup(props) {
    const Route = useRouter()
    console.log(Route)
    const state = reactive({
      menuList: Route.options.routes[2].children,
    })

    const handleCommand = (command) => {
      console.log(command)
    }
    onMounted(() => {})
    return {
      ...toRefs(state),
      handleCommand,
    }
  },
}
</script>

<style scoped lang="scss">
.main-aside {
  background: #fff;
  padding-left: 20px;
  float: left;
  position: sticky;
  top: 80px;
  margin-right: 20px;
  .el-aside {
    background: #fff;
    height: calc(100vh - 100px);
    box-sizing: border-box;
    display: inline-flex;
    flex-direction: column;
    outline: none;
    overflow: hidden;
    overflow-y: auto;
    .iconfont {
      margin-right: 16px;
      color: #37383c;
    }
  }
}
.pusb-course {
  width: 200px;
  height: 38px;
  background: #4e70f2;
  border-radius: 2px;
  color: #fff;
  margin: 30px 0 20px;
  display: block;
}
</style>
